var Md5 = require('../../utils/md5.js');
var timeSecond = Math.floor(Date.now() * 0.001);  //获取时间戳: 
var SignInfoData = Md5.hexMD5(timeSecond + 'nativetalk')//md5加密;
var httpFile = 'http://file.waijiaojun.com/';
const app = getApp();
var httpNativetalk = app.globalData.httpNativetalk;
var httpWeike = app.globalData.httpWeike;
Page({
  data: {
    imgUrl: 'http://file.waijiaojun.com/waijiaojun/icon',
  },
  onLoad: function (options) {    
    var that = this;
    wx.request({
      url: httpWeike + '/payment/token/student/wallet',
      data: {},
      header: {
        "Timestamp": timeSecond,
        "SignInfo": SignInfoData,
        "content-Type": "application/json",
        "client_type": "3",
        "version": 15,
        "token": app.globalData.token,
      },
      method: 'POST',
      success: function (res) {
        console.log(res);
        var billsData = res.data.obj.bills.data;
        function getDate(time) {
          var date = new Date(time);
          var Y = date.getFullYear() + '-';
          var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
          var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
          var H = date.getHours() < 10 ? '0' + date.getHours() : date.getHours() + ':';
          var Min = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
          return (Y + M + D + ' ' + H + D);
        };
        for (var i = 0; i < billsData.length; i++) {
          billsData[i].createOrderTime = getDate(billsData[i].createOrderTime);
          if (billsData[i].actionType == -1) {
            billsData[i].actionType = "-"
          }
          if (billsData[i].actionType == 1) {
            billsData[i].actionType = "+"
          }
        }
        that.setData({
          billsData: billsData,
          balanceMoney: res.data.obj.balance,
        })

      },
      fail: function (res) { },
      complete: function (res) { },


    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})